using UnityEngine;

public class TargetLine : MonoBehaviour
{
	private SpriteRenderer spriteRenderer;

	private float minScoredLiquidLevel;

	private float maxScoredLiquidLevel;

	public LiquidType liquidType;

	private float lineWidth;

	private bool upperLimitReachingToGlassEdge;

	private void Awake()
	{
		spriteRenderer = GetComponent<SpriteRenderer>();
	}

	public void SetTargetLine(LiquidType liquidType, float lineWidth, float lowerLiquidExtent, float upperLiquidExtent)
	{
		this.liquidType = liquidType;
		if (spriteRenderer == null)
		{
			spriteRenderer = GetComponent<SpriteRenderer>();
		}
		this.lineWidth = lineWidth;
		spriteRenderer.color = Globals.instance.liquidColorsDataManager.GetColorDataForLiquid(liquidType).liquidLine;
		ComputeMinAndMaxLiquidLevel(lowerLiquidExtent, upperLiquidExtent);
	}

	public void SetTargetLineAsReachingGlassEdge(float upperGlassEdge)
	{
		upperLimitReachingToGlassEdge = true;
		Vector3 position = base.transform.position;
		maxScoredLiquidLevel = position.y + upperGlassEdge;
	}

	public void ShowTargetLine()
	{
		LineAlphaTween(1f);
		LineWidthTween(0f);
		iTween.ValueTo(base.gameObject, iTween.Hash("from", 0f, "to", lineWidth, "onupdate", "LineWidthTween", "time", 0.5f));
	}

	public void HideTargetLine()
	{
		iTween.ValueTo(base.gameObject, iTween.Hash("from", 1f, "to", 0f, "onupdate", "LineAlphaTween", "time", 0.4f));
	}

	private void LineAlphaTween(float alpha)
	{
		Color color = spriteRenderer.color;
		color.a = alpha;
		spriteRenderer.color = color;
	}

	private void ComputeMinAndMaxLiquidLevel(float lowerLiquidExtent, float upperLiquidExtent)
	{
		Vector3 position = base.transform.position;
		minScoredLiquidLevel = position.y - lowerLiquidExtent;
		Vector3 position2 = base.transform.position;
		maxScoredLiquidLevel = position2.y + upperLiquidExtent;
	}

	private void LineWidthTween(float value)
	{
		Vector2 size = spriteRenderer.size;
		size.x = value;
		spriteRenderer.size = size;
	}

	public bool IsLiquidLevelAboveScoredRange(float liquidLevel)
	{
		if (liquidLevel > maxScoredLiquidLevel)
		{
			return true;
		}
		return false;
	}

	public bool IsLiquidLevelBelowScoredRange(float liquidLevel)
	{
		if (liquidLevel < minScoredLiquidLevel)
		{
			return true;
		}
		return false;
	}

	public float GetScoreOfLiquidLevel(float liquidLevel)
	{
		Vector3 position = base.transform.position;
		float num = Mathf.Abs(position.y - liquidLevel);
		Vector3 position2 = base.transform.position;
		float num3;
		if (liquidLevel > position2.y)
		{
			float num2 = maxScoredLiquidLevel;
			Vector3 position3 = base.transform.position;
			num3 = num2 - position3.y;
		}
		else
		{
			Vector3 position4 = base.transform.position;
			num3 = position4.y - minScoredLiquidLevel;
		}
		float num4 = 1f - num / num3;
		if (num4 < 0f)
		{
			num4 = 0f;
		}
		if (upperLimitReachingToGlassEdge)
		{
			num4 = AidScoreReachingGlassEdge(num4);
		}
		return num4;
	}

	private float AidScoreReachingGlassEdge(float score)
	{
		score = ((score <= 0.4f) ? 0.5f : ((!(score <= 0.8f)) ? 1f : 0.8f));
		return score;
	}
}
